#include <string.h>
#include "pgp.h"

boolean strip_spaces;
int version_byte = VERSION_BYTE_NEW;

char KEY_EXTENSION[] = ".key";
char BAK_EXTENSION[] = ".bak";

char globalRandseedName[MAX_PATH];

/* Various compression signatures: PKZIP, Zoo, GIF, Arj, and HPACK.
   Lha(rc) is handled specially in the code; it is missing from the
   compressSig structure intentionally.  If more formats are added,
   put them before lharc to keep the code consistent.

   27-Jun-95 simons@peti.rhein.de (Peter Simons)
   Added support for lh5 archive as generated by Lha. Unfortunately,
   Lha requires special treatment also. I inserted the check right
   _before_ lharc, because lh5/lha is a special type of an lharc
   archive.
 */
static char *compressSig[] =
{"PK\03\04", "ZOO ", "GIF8", "\352\140",
 "HPAK", "\037\213", "\037\235", "\032\013", "\032HP%"
		/* lharc is special, must be last */ };
static char *compressName[] =
{"PKZIP", "Zoo", "GIF", "Arj",
 "Hpack", "gzip", "compressed", "PAK", "Hyper",
 "Lha", "Lharc"};
static char *compressExt[] =
{".zip", ".zoo", ".gif", ".arj",
 ".hpk", ".gz", ".Z", ".pak", ".hyp",
 ".lha", ".lzh"};

/* "\032\0??", "ARC", ".arc" */

/* Returns file signature type from a number of popular compression formats
   or -1 if no match */
int compressSignature(byte * header)
{
	int i;

	for (i = 0; i < sizeof(compressSig) / sizeof(*compressSig); i++)
		if (!strncmp((char *) header, compressSig[i], strlen(compressSig[i])))
			return i;

	/* Special check for lha files */
	if (!strncmp((char *)header+2, "-lh5-", 5))
	  return i;

	/* Special check for lharc files */
	if (header[2] == '-' && header[3] == 'l' &&
		(header[4] == 'z' || header[4] == 'h') &&
		header[6] == '-')
		return i+1;
	return -1;
}								/* compressSignature */

char sErrorText[1000];
long nErrorCode;
jmp_buf jbuf;
int errorLvl = EXIT_OK;

/*
 * exitPGP: wipes and removes temporary files, also tries to wipe
 * the stack.
 */
void exitPGP(int returnval)
{
/*		IPrivClearResources(); */
#ifdef VMS
/*
 * Fake VMS style error returns with severity in bottom 3 bits
 */
	if (returnval)
		returnval = (returnval << 3) | 0x10000002;
	else
		returnval = 0x10000001;
#endif							/* VMS */
		nErrorCode = returnval;
	longjmp(jbuf, returnval);
}

/* comes here if user made a boo-boo. */
void user_error()
{
	exitPGP(errorLvl ? errorLvl : 127); 		/* error exit */
}
